import time

from appium.webdriver.common.appiumby import AppiumBy
from base.base_object import Authorize_Object, Home_object


#定义page,继承object中的元素
class Authorize_page(Authorize_Object):
        #定位一个元素的点击方法
        def privacy_agree_click(self,driver):
        #把元素定位方式传进去AppiumBy.XPAHT
        #把元素定位值传进去(object中封装的属性值)
            # return driver.find_element(AppiumBy.XPATH,self.privacy_agree_button()).click()
            return self.click_new(driver=driver,by=AppiumBy.XPATH,value=self.privacy_agree_button())
        def authorize_agree_click(self,driver):
            return self.click_new(driver=driver,by=AppiumBy.XPATH,value=self.authorize_agree_button())
        def ad_close_click(self,driver):
            return self.click_new(driver=driver,by=AppiumBy.XPATH,value=self.ad_close_button())
        # 将3步授权的操作组装到一起
        def authorize_step(self, driver):
            self.privacy_agree_click(driver)
            self.authorize_agree_click(driver)
            self.ad_close_click(driver)


class Home_Page(Home_object):
    #点击放大镜
    def home_search_bar_click(self,driver):
        return self.click_new(driver=driver,by=AppiumBy.XPATH,value=self.home_search_bar_button())
    #输入内容
    def home_search_bar_sendkeys (self,driver,text):
        return self.send_keys_new(driver=driver,by=AppiumBy.XPATH,value=self.home_search_bar_textview(),text=text)
    #组装成刻业务
    def home_search_step(self,driver,text):
        self.home_search_bar_click(driver)
        self.home_search_bar_sendkeys(driver,text)

# if __name__ == '__main__':
#     #导入打开app的方法
#     from config.comm_driver import CommonDriver
#     dr = CommonDriver().get_driver()
#     # #调用page中的元素点击操作
#     # Authorize_page().privacy_agree_click(dr)
#     # Authorize_page().authorize_agree_click(dr)
#     # Authorize_page().ad_close_click(dr)
#     Authorize_page().authorize_step(dr)
#     #调用page中的元素点击操作
#     Authorize_page().click_new(dr,AppiumBy.XPATH,'//android.widget.TextView[@text=""]')
#     Authorize_page().send_keys_new(dr,AppiumBy.ID,'com.dangdang.buy2:id/et_search','123456')
#     time.sleep(3)
#     Authorize_page().send_keys_new(dr,AppiumBy.ID,'com.dangdang.buy2:id/et_search','789789')

if __name__ == '__main__':
    import time
    from appium.webdriver.common.appiumby import AppiumBy
    from config.comm_driver import CommonDriver
    from page.authorize_page import Authorize_page

    dr = CommonDriver().get_driver()
    Authorize_page().authorize_step(dr)
    Home_Page().home_search_step(dr, '天下无双')
    time.sleep(3)
    Home_Page().home_search_step(dr, '一剑开天门')